import java.util.Arrays;
import java.util.Scanner;

/**
 *
 */
public class Leetcode390 {
    public static void main(String[] args) {
        int max = (int) Math.pow(10, 9);

        int k[] = new int[max];
        for (int i = 1; i <= max; i++) {
            k[i] = lastRemaining(i);
        }

        System.out.println(Arrays.toString(k));
    }

    public static int lastRemaining(int n) {
        if (n == 1) {
            return 1;
        }

        return 2 * (n / 2 - lastRemaining(n / 2) + 1);
    }

}

